package com.cloud.controller.good;

import com.cloud.bean.good.Good;
import com.cloud.bean.menu.Menu;
import com.cloud.common.BaseReturn;
import com.cloud.service.good.GoodService;
import com.cloud.service.menu.MenuService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

@RestController
@RequestMapping("/api/good")
public class ApiGoodConteroller {

    @Autowired
    GoodService goodService;
    @Autowired
    MenuService menuService;

    @RequestMapping("/list")
    public BaseReturn list(@RequestBody ApiGoodData apiMenuGoodData){
        List<Menu> menus = menuService.list();

        List<ApiGoodData> goodMenus = new ArrayList<>();
        for (Menu menu: menus) {
            ApiGoodData apiGoodData = new ApiGoodData();
            apiGoodData.setName(menu.getName());
            apiGoodData.setMenuId(menu.getId());
            List<Good> goods = goodService.listByMenuId(menu.getId());
            apiGoodData.setFoods(goods);
            goodMenus.add(apiGoodData);
        }

        return BaseReturn.build("2000","查询成功",goodMenus);
    }

}
